package com.gnerv.cms.controller;

import com.gnerv.cms.common.Result;
import com.gnerv.cms.dto.SessionDTO;
import com.gnerv.cms.service.ISessionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 基础平台-session controller
 *
 * @author zhang
 * @date 2019/12/4
 **/
@Api(tags = "会话管理")
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/api/manage/session")
public class SessionController {


    @Resource
    private ISessionService sessionService;

    @RequestMapping(value = "/logout/{sessionId}", method = RequestMethod.GET)
    private Result logout(@PathVariable("sessionId") String sessionId) {
        sessionService.logout(sessionId);
        return new Result();
    }

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Result listSession() {
        List<SessionDTO> sessions = sessionService.listSession();
        return new Result().data("sessions", sessions);
    }
}
